package com.tico.common.utils;

import com.tico.common.pojo.BaseParam;
import lombok.Data;

import java.util.List;

@Data
public class PageResult<T> {
    private T result;
    private int pageNum = 1;
    private int pageSize = 10;
    private long total = 0;
    private int totalPageCount = 0;
    private boolean hasNext = true;
    private long max_order_num;


    public PageResult() {
    }

    public PageResult(int pageNum, int pageSize) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
    }

    public PageResult(int pageNum, int pageSize, int total) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.total = total;
    }

    public PageResult(int pageNum, int pageSize, boolean hasNext) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.hasNext = hasNext;
    }

    public PageResult(T result) {
        this.result = result;
    }

    public PageResult(T result, int pageNum, int totalPageCount, int pageSize) {
        this.result = result;
        this.pageNum = pageNum;
        this.total = totalPageCount;
        this.pageSize = pageSize;
    }

    public PageResult(int pageNum, int pageSize, long total, T result) {
        this.result = result;
        this.pageNum = pageNum;
        this.total = total;
        this.pageSize = pageSize;
    }

    public boolean isHasNext() {
        if (getCurrentPage() >= getTotalPageCount()) {
            return false;
        }
        return true;
    }

    public void setHasNext(boolean hasNext) {
        this.hasNext = hasNext;
    }

    public Integer getTotalPageCount() {
        return ((int) total + pageSize - 1) / pageSize;
    }

    public Integer getCurrentPage() {
        if (pageNum < 0) {
            return 1;
        } else if (pageNum > getTotal()) {
            return getTotalPageCount();
        } else {
            return pageNum;
        }
    }
}
